package xin3.demo3;

    /**
    * 1.this 关键字
     *      Student区间内this指Student类本身
     *      使用this可以使用类的其他属性和方法
     * 2.static 关键字
    */
    class Student{
        String id;
        String name;
        private int age;
        private int gender;//0男 1女
        String dep = "信息系";
        static String hobby = "健身";

        public  Student(String ID){//方法名称和类名一致 叫做构造方法
            id = ID;
        }
        //利用重载技术 构造方法重载
        public Student(){

        }
        void read(){
            System.out.println("大家好，我是"+name+".我在看书");
        }

        void setAge(int a){//设置年龄
            this.age = age;// Student区间内this指Student类本身
            if (age < 0 || age > 150){
                System.out.println("你输入的年龄有误");
            }else {
                this.age = age;
            }
        }
        int getAge(){//获取年龄
            return age;
        }
        // 转化形变汉字到数字
        void setGender(String g){
            if (g.equals("男")){
                gender = 0;
            }
            else if (g.equals("女")){
                gender = 1;
            }else{
                System.out.println("性别有误");
            }
        }
        String getGender(){
            if(gender == 0){
                return "男";
            }else{
                return "女";
            }
        }
    }
public class Demo3 {
    public static void main(String[] args) {
        Student stu1 =new Student();
        stu1.setAge(18);
        Student stu2 = new Student();
        System.out.println(stu1.dep);
        System.out.println(stu2.dep);
        stu1.dep = "宇宙系";
        System.out.println("修改stu1后系部信息");
        System.out.println(stu1.dep);
        System.out.println(stu2.dep);
        System.out.println("***********");
        System.out.println(stu1.hobby);
        System.out.println(stu2.hobby);
        stu1.hobby = "抽烟";
        System.out.println("学生1爱好static属性变化");
        System.out.println(stu1.hobby);
        System.out.println(stu2.hobby);
    }
}
